﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

using DAL;
using BLL;
using CTRL;

namespace WCF
{
    public class Service : IService
    {
        #region BatteryItem
        public BatteryItem GetBatteryItem(int ID)
        {
            CtrlBatteryItem batItemController = CtrlBatteryItem.Instance;
            return batItemController.GetBatteryItem(ID);
        }

        public void UpdateBatteryState(BatteryItem item, BatteryState state)
        {
            CtrlBatteryItem batItemController = CtrlBatteryItem.Instance;
            batItemController.UpdateBatteryState(item, state);
        }

        public int UpdateBatteryItem(int ID, int _modelID, string stationName, BatteryState _state)
        {
            CtrlBatteryItem batItemController = CtrlBatteryItem.Instance;
            return batItemController.UpdateBatteryItem(ID, _modelID, stationName, _state);
        }
        
        public IEnumerable<BatteryItem> FindBatteryItemsAtLocationState(string location, double capacity, BatteryState state)
        {
            CtrlBatteryItem batItemController = CtrlBatteryItem.Instance;
            return batItemController.FindBatteryItemsAtLocationState(location, capacity, state);
        }
        #endregion
        #region BatteryStation
        public BatteryStation GetBatteryStationByID(int stationID)
        {
            CtrlBatteryStation batStatController = CtrlBatteryStation.Instance;
            return batStatController.GetBatteryStationByID(stationID);
        }

        public BatteryCenter FindBatteryCenter(string name)
        {
            CtrlBatteryStation batStatController = CtrlBatteryStation.Instance;
            return batStatController.FindBatteryCenter(name);
        }
        #endregion
        #region BookingItem
        public IEnumerable<BookingItem> GetBookingItemsFromBooking(int bookingID)
        {
            CtrlBookingItem bookItemController = CtrlBookingItem.Instance;
            return bookItemController.GetBookingItemsFromBooking(bookingID);
        }
        #endregion
        #region Booking
        public Booking GetBooking(int bookingID)
        {
            CtrlBooking bookingController = CtrlBooking.Instance;
            return bookingController.GetBooking(bookingID);
        }

        public List<Booking> GetAllBookingsOfCustomer(int customerID)
        {
            CtrlBooking bookingController = CtrlBooking.Instance;
            return bookingController.GetAllBookingsOfCustomer(customerID);
        }

        public int CreateBooking(int carID, List<BatteryCenterDistance> bcdList)
        {
            CtrlBooking bookingController = CtrlBooking.Instance;
            return bookingController.CreateBooking(carID, bcdList);
        }

        public Dictionary<BatteryCenter, BatteryItem> ReserveBatteries(List<BatteryCenterDistance> listBCD, Car car)
        {
            CtrlBooking bookingController = CtrlBooking.Instance;
            return bookingController.ReserveBatteries(listBCD, car);
        }

        public void UnReserveBatteries(List<BatteryItem> listBatteryItem)
        {
            CtrlBooking bookingController = CtrlBooking.Instance;
            bookingController.UnReserveBatteries(listBatteryItem);
        }

        public int CancelBooking(int bookingID)
        {
            CtrlBooking bookingController = CtrlBooking.Instance;
            return bookingController.CancelBooking(bookingID);
        }

        public bool CanCancelBooking(int bookingID)
        {
            CtrlBooking bookingController = CtrlBooking.Instance;
            return bookingController.CanCancelBooking(bookingID);
        }
        #endregion
        #region Car
        public Car GetCar(int carID)
        {
            CtrlCar carController = CtrlCar.Instance;
            return carController.GetCar(carID);
        }

        public IEnumerable<Car> GetAllCarsOwnedByCustomer(int customerID)
        {
            CtrlCar carController = CtrlCar.Instance;
            return carController.GetAllCarsOwnedByCustomer(customerID);
        }

        public Car FindCarByLicencePlate(string licencePlate)
        {
            CtrlCar carController = CtrlCar.Instance;
            return carController.FindCarByLicencePlate(licencePlate);
        }

        public int CreateCar(double range, double capacity, int _customerID, string _licencePlate)
        {
            CtrlCar carController = CtrlCar.Instance;
            return carController.CreateCar(range, capacity, _customerID, _licencePlate);
        }

        public int UpdateCar(int ID, double range, double capacity, int _customerID, string _licencePlate)
        {
            CtrlCar carController = CtrlCar.Instance;
            return carController.UpdateCar(ID, range, capacity, _customerID, _licencePlate);
        }
        public int DeleteCar(int ID)
        {
            CtrlCar carController = CtrlCar.Instance;
            return carController.DeleteCar(ID);
        }
        #endregion
        #region Customer
        public Customer CheckLoginCredentials(string name, string password)
        {
            CtrlCustomer custController = CtrlCustomer.Instance;
            return custController.CheckLoginCredentials(name, password);
        }
        #endregion
        #region Map
        public IList<BatteryCenter> GetAllCities()
        {
            CtrlMap mapController = CtrlMap.Instance;
            return mapController.GetAllCities();
        }

        public BatteryCenter FindCity(string name)
        {
            CtrlMap mapController = CtrlMap.Instance;
            return mapController.FindCity(name);
        }

        public List<BatteryCenterDistance> GetPathFromCityToCity(BatteryCenter from, BatteryCenter to, double carRange)
        {
            CtrlMap mapController = CtrlMap.Instance;
            return mapController.GetPathFromCityToCity(from, to, carRange);
        }
        #endregion
    }
}
